<?php
/**
 * Created by PhpStorm.
 * User: wangan
 * Date: 2016/12/21
 * Time: 10:17
 */

namespace App\Http\Controllers\Ceb;


use Illuminate\Http\Request;
use App\Http\Controllers\Ceb\BaseController as Controller;
use App\Components\CebApiRequest;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use App\Constants\CebApi;

class AdvertistmentController extends Controller
{
    public function index(Request $request){
        $int_Page = $request->get('page',1);
        $int_PageSize = $request->get('pageSize',10);
        $int_Platform = $request->get('platform',1);

        $request_Ad = new CebApiRequest();
        $res_Ad = $request_Ad->invoke(CebApi::ADVERTISEMENT_LIST,[
            'page'=>$int_Page,
            'page_size'=>$int_PageSize,
            'platform'=>$int_Platform,
        ]);
        $arr_AdList = $res_Ad->data('list');
        $int_AdCount = $res_Ad->data('count');

        $paginator =new LengthAwarePaginator([], $int_AdCount,$int_PageSize, $int_Page, [
            'path' => Paginator::resolveCurrentPath(),
            'pageName' => 'page',
        ]);
        return $this->view('advertistment.index',[
            'ad_list'=>$arr_AdList,
            'paginator'=>$paginator,
        ]);
    }

    public function create(Request $request){
        $request_Ad = new CebApiRequest();
        $res_AdTypes = $request_Ad->invoke(CebApi::ADVERTISMENT_TYPES);
        $arr_Types = $res_AdTypes->data('list');

        $res_AdPlace = $request_Ad->invoke(CebApi::ADVERTISMENT_SHOWPLACE);
        $arr_Places = $res_AdPlace->data('list');

        return $this->view('advertistment.create',[
            'type_list' => $arr_Types,
            'place_list' => $arr_Places,
        ]);
    }

    public function store(){

    }

    public function edit(Request $request){
        $id = $request->get('id');

        $request_Ad = new CebApiRequest();
        $res_Ad = $request_Ad->invoke(CebApi::ADVERTISMENT_SHOW,['id'=>$id]);
        $arr_AdInfo = $res_Ad->data('advertisment');

        return view('advertistment.edit',[
            'info'=>$arr_AdInfo,
        ]);
    }

    public function doEdit(){

    }




}